package com.nondo.rdp.auth.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.nondo.rdp.core.domain.base.BaseEntity;

/**
 * 我的-消息中心
 */
@Entity
@Table(name = "sys_user_message")
public class UserMessage extends BaseEntity {
	private static final long serialVersionUID = 2751850695642989116L;
	private Long id; // 主键 ID;
	private Message message; // 消息
	private User user; // 用户
	private int isRead; // 已读
	
	//扩展字段
	private Integer type;
	private Long uid;

	@Id
    @GeneratedValue(strategy= GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@OneToOne
	@JoinColumn (name = "mid")
	public Message getMessage() {
		return message;
	}

	public void setMessage(Message message) {
		this.message = message;
	}

	@JsonIgnore
	@OneToOne
	@JoinColumn (name = "uid")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Column(columnDefinition = "int default 0", nullable = false)
	public int getIsRead() {
		return isRead;
	}

	public void setIsRead(int isRead) {
		this.isRead = isRead;
	}

	@JsonIgnore
	public Integer getType() {
		return type;
	}

	@JsonSetter
	public void setType(Integer type) {
		this.type = type;
	}

	@Transient
	public Long getUid() {
		uid = user.getId();
		return uid;
	}

	public void setUid(Long uid) {
		this.uid = uid;
	}

}
